import Result from "../domain/vo/Result.js"
import CourseServiceImpl from "../service/CourseService.js"

const courseService = new CourseServiceImpl()

const getCourseList = () => {
    return Result.success(courseService.getCourseList())
}


const getCourseListByTag = (tag, page, limit) => {
    if (!page) {
        page = 1
    }else if (!limit) {
        limit = 25
    }
    return Result.success(courseService.getCourseListByTag(tag, page, limit))
}

const getHotCourseList = (tag) => {
    return Result.success(courseService.getHotCourseList(tag, 8))
}

const getRecommendCourseList = (tag) => {
    return Result.success(courseService.getRecommendCourseList(tag, 6))
}

const getCourseDetail = (id) => {
    return Result.success(courseService.getCourseDetail(id))
}

export const buildController = () => {

    return {
        "/course/list": getCourseList,
        "/course/list/tag": getCourseListByTag,
        "/course/list/hot": getHotCourseList,
        "/course/list/recommend": getRecommendCourseList,
        "/course/detail": getCourseDetail,
    }

}